#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main()
{
    int count = 100;
    __pid_t pid = fork();//成功返回两次，一次给父进程，一次给子进程。子进程复制父进程的代码段，数据段，堆栈段，但pid不同，两者相互独立
    printf("pid: %d\n", pid);
    if (pid == -1)
    {
        perror("fork failed");
        exit(EXIT_FAILURE);
    }
    else if (pid == 0)//子进程
    {
        count++;
        printf("Child process count: %d\n", count);
        printf("Child process %d\n", getpid());
    }
    else//父进程
    {
        count++;
        printf("Parent process count: %d\n", count);
        printf("Parent process %d\n", getpid());
    }
    printf("Hello World\n");
    return 0;
}